﻿namespace EyeOpen.Data.EntityFramework
{
	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Data.Entity;
	using System.Linq;
	using System.Linq.Expressions;

	internal class Repository<T>
		: IRepository<T>
		where T : class
	{
		private readonly IDbSet<T> set;
		private readonly IQueryable<T> queryable;

		public Repository(IDbSet<T> set)
		{
			this.set = set;
			this.queryable = set.AsQueryable();
		}

		public Expression Expression
		{
			get
			{
				return
					this.queryable.Expression;
			}
		}

		public Type ElementType
		{
			get
			{
				return
					this.queryable.ElementType;
			}
		}

		public IQueryProvider Provider
		{
			get
			{
				return
					this.queryable.Provider;
			}
		}

		public void Add(T entity)
		{
			this.set.Add(entity);
		}

		public IEnumerator<T> GetEnumerator()
		{
			return
				this.queryable.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return this.GetEnumerator();
		}
	}
}
